﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebSite.QuestionnairHandle;
using System.Collections.Generic;

public partial class WebSite_m_paper_edit : System.Web.UI.Page
{
    string userid,paperid;
    string questionTitle, Location;
    int Count = 1;
    QuestionnaireHandler handler;
    Dictionary<string, string> Content;
    protected void Page_Load(object sender, EventArgs e)
    {
        handler=new QuestionnaireHandler();
        if (Session["UserId"] == null || Session["UserIdentity"].ToString() != "2")
        {
            Response.Redirect("Default.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            return;
        }
        userid = Session["UserId"].ToString();

        if (Request["PaperId"] != null)
        {
            //如果是修改问卷则找到问卷
            paperid = Request["PaperId"].ToString();
            //通过问卷Id获得问卷
            DataSet ds = handler.GetQuestionnaireResultById(int.Parse(paperid));
            if (ds.Tables[0].Rows.Count>0)
            {
                //问卷名称
                questionTitle=ds.Tables[0].Rows[0]["QuestionnairName"].ToString();
                //问卷xml文件名
                Location = ds.Tables[0].Rows[0]["Location"].ToString();
                Count = handler.QuestionCount(Location);
                for (int i = 0; i < Count;i++ )
                {

                    Content=handler.GetQuestionByNum(Location,i+1);
                    AddQuestion(Content, i+1);

                }
                
            }
            
        }
        else paperid = "";

        return;
    }
    //增加选项
    private void AddItem(Dictionary<string,string>)
    {
        TableRow row = new TableRow();
        TableCell cellHead = new TableCell();
        TableCell cellContent = new TableCell();
        Label LabelAuditing = new Label();
        TextBox TextAuditing = new TextBox();
        LabelAuditing.ID = "ItemNameLabel" + num.ToString();
        LabelAuditing.Text = "选项" + (num).ToString() + ":";
        TextAuditing.ID = "ItemTextBox" + num.ToString();
        TextAuditing.Height = 18;

        cellHead.Controls.Add(LabelAuditing);
        cellContent.Controls.Add(TextAuditing);
        cellHead.BackColor = System.Drawing.Color.FromName("#EFEFEF");
        cellHead.HorizontalAlign = HorizontalAlign.Right;
        cellHead.Width = 100;
        cellContent.BackColor = System.Drawing.Color.FromName("#EFEFEF");
        cellContent.HorizontalAlign = HorizontalAlign.Left;
        cellContent.Width = 400;
        row.Cells.Add(cellHead);
        row.Cells.Add(cellContent);
    }
    protected void AddBtn_Click(object sender, EventArgs e)
    {

    }
    protected void UploadBtn_Click(object sender, EventArgs e)
    {

    }
    protected void CancelBtn_Click(object sender, EventArgs e)
    {

    }
}
